<?php
namespace app\index\controller;
use Doctrine\Common\Cache\SQLite3Cache;
use think\Controller;
use app\extra\Sql;
class Index extends Controller
{
    /**
     * @return array|mixed|\think\response\View
     * 首页
     */
    public function index()
    {

        $data['user'] = session('user') ? session('user') : '';
        //分类信息
        $category1 = Sql::_select('category');
        foreach($category1 as $v){
            $category2[$v['id']]=$v;
        }
        $data['categoryArr'] = $category2;

        $get = request()->get();
        $data['status'] = $get['status']?$get['status']:0;
        $data['category'] = $get['category']?$get['status']:0;
        $where['is_checked'] = 1;
        if($get['status'] != 0){
            $where['status'] = $get['status'];
        }
        if($get['category'] != 0){
            $where['category_id'] = $get['category'];
        }
        //查询数据并分页
        $list = Sql::_selectPage(
            'problem',
            $where,
            '',
            2,
            $_GET,
            [],
            '*',
            $_GET['page']
        );
        $data['list'] = $list->items();
        $data['page'] = $list->render();

        return view('index',$data);
    }
    public function problem(){
        $post = request()->post();
        $post['mobile'] = $post['mobile']? $post['mobile'] :'';
        $post['content1'] = $post['content1']?$post['content1']:'';
        return view('ask',$post);
    }
    public function doProblem(){
        $post = request()->post();
        $data['content'] = $post['content'];
        $data['mobile'] = $post['mobile'];
        $data['create_at'] = time();
        Sql::_save('problem',$data);
        return view('do_ask');
    }
    public function lawyer(){
        $sql = "select * from tp_user as user left join tp_lvshi as lvshi on user.id=lvshi.user_id where type=2 and status=1 ";
        $data['list'] = Sql::_query($sql);
        return view('lawyer',$data);
    }
    public function pay(){
        $id = request()->get('id');
        $sql = "select * from tp_user as user left join tp_lvshi as lvshi on user.id=lvshi.user_id where type=2 and status=1 and user.id={$id}";
        $data['list'] = Sql::_query($sql);
        return view('lawyer',$data);
    }
    public function ans(){
        //咨询回复页
        $get = request()->get();
        $id = $get['id']?$get['id']:1;
        $where['id'] = $id;
        $data['problem'] = Sql::_find('problem',$where);
    }

}
